package com.abbas.smartCity.base

import android.os.Bundle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.abbas.smartCity.util.NoImpl
import java.lang.reflect.ParameterizedType

/**
 * 使用了 ViewBinding/ViewModel
 * 子类持有须持有ViewBinding、ViewModel
 * 填入泛型后，直接使用 binding、viewModel
 */
@NoImpl
abstract class BaseBindingModelActivity<VB: ViewBinding,VM: ViewModel>: BaseBindingActivity<VB>() {

    protected lateinit var viewModel: VM

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        var parameterizedType = javaClass.genericSuperclass as ParameterizedType
        var clazz = parameterizedType.actualTypeArguments[1] as Class<ViewModel>
        viewModel = ViewModelProvider(this, ViewModelProvider.NewInstanceFactory()).get(clazz) as VM
    }
}